from Tkinter import *
from simify import *

generator = PolygonToSimlist([0+0j, .25+.25j, .25+.75j, .75+.75j, .75+.25j, 1+0j])
transforms=[Similarity( 0+.5j, 0, flip=1),
            Similarity( .5+0j, 0+.5j ),
            Similarity( .5+0j, .5+.5j ),
            Similarity( 0-.5j, 1+.5j, flip=1 )]
         

triangle = PolygonToSimlist([-.5+0j, 0+1j, .5+0j, -.5+0j])

def drawhilbert(i, last, canvas):
    simlist = generator
    for j in range(i):
        simlist = ChainSims(transforms, simlist)
    curve = canvas.create_line(*SimlistToPixels(simlist, 600, 600, .5+.5j,1))
    if i < last:
        window.after(1000, canvas.delete, curve)
    if i < last:
        window.after(1000, drawhilbert, i+1, last, canvas)

window = Tk()
window.title("Hilbert's space-filling curve")
canvas = Canvas(window, width=600, height=600)
canvas.pack()
drawhilbert(0, 6, canvas)
window.mainloop()
